<?php
namespace addons\hellozjx_mapwxapp\inc\page;

trait User 
{
	/**
	 * 会员-我的-课程列表
	 * @return [type] [description]
	 */
	public function doPageCourseList()
	{
		$openId = self::$_GPC['openId']; // 当前用户的openId
		// 求出会员 id
		$user = pdo_get($this->table_user, array('openid' => $openId));
		// 求出该会员的的订单
		$orderList = pdo_getAll($this->table_order, array('uid' => $user['id']), array('vid'));
		// 求出视频系列
		$sql = "select a.id, a.name, a.img_url, b.name as teacher_name from " . tablename($this->table_video) . " as a left join " . tablename($this->table_teacher) . " as b ON a.teacher_id = b.id group by a.series_id";
		$videoSeries = pdo_fetchall($sql);
		
		return $this->result(0, '', $videoSeries);
	}

	/**
	 * 会员注册
	 * @return [type] [description]
	 */
	public function doPageUserRegister()
	{
		$openid = self::$_W['openid'];
		$uniacid = self::$_W['uniacid'];
		$user = pdo_get($this->table_user, array('openid' => $openid));
		if (!empty($user)) {
			return $this->result(0, '成功');
		}

		$data = array(
			'real_name' => self::$_GPC['real_name'],
			'sex' => self::$_GPC['sex'],
			'phone' => '',
			'email' => '',
			'address' => '',
			'status' => 1,
			'nick_name' => self::$_GPC['nick_name'],
			'avatar' => self::$_GPC['avatar'],
			'openid' => $openid,
			'create_time' => date('Y-m-d H:i:s')
		);
		$teacher = pdo_insert($this->table_user, $data);
		if (empty($teacher)) {
			return $this->result(-1, '会员信息插入失败', []);
		}
		return $this->result(0, '成功');
	}
}